<template>
  <div class="usercollect-container nav-bar-top">
    <van-nav-bar class="nav-bar" title="我的收藏" :right-text="listView.list.length > 0 ? editFlag ? '完成' : '编辑' : ''" left-arrow  @click-right="editFlag = !editFlag" @click-left="$router.back()"/>
    <van-list v-if="showList"
      v-model="listView.loading"
      :finished="listView.finished"
      finished-text="没有更多了"
      @load="loadList">
      <div class="order-goods-list circle-bg" v-for="(item, index) in listView.list" :key="index">
        <div class="goods-sel" v-if="editFlag">
          <van-checkbox v-model="item.checked" @click="checkItem(item)"></van-checkbox>
        </div>
        <div class="order-goods-item">
          <van-image class="goods-img" :src="item.mallGoods.pic" @click="checkItem(item)"/>
          <div class="goods">
            <span @click="$router.push({path: '/goodsDetail', query: {id: item.mallGoods.id}})" class="title van-multi-ellipsis--l2">{{item.mallGoods.name}}</span>
            <span class="num">{{item.checked}}</span>
            <div class="price">
              <span><em>¥</em>{{item.mallGoods.price | fentoyuan}}</span>
            </div>
          </div>
        </div>
      </div>
    </van-list>
    <!-- 结算 -->
    <div class="van-submit-bar-box">
      <van-submit-bar button-text="删除" v-if="listView.list.length > 0 && editFlag">
        <van-checkbox :value="allChecked">全选</van-checkbox>
      </van-submit-bar>
    </div>
    <van-empty v-if="!showList"
      image="imgs/empty.png"
      description="暂无收藏记录~"
    />
  </div>
</template>

<script>
import { mapState } from 'vuex'
import constants from '@/config/constants'
import userApi from '@/api/userApi'
import utils from '@/utils/utils'

export default {
  name: 'userCollect',
  computed: {
    ...mapState(['user'])
  },
  data () {
    return {
      /* 编辑状态 */
      editFlag: false,
      allChecked: false,

      showList: true,
      /* 积分流水列表 */
      listView: {
        params: {
          pageNo: 1,
          pageSize: 10
        },
        loading: false,
        finished: false,
        list: []
      }
    }
  },
  methods: {
    /* 获取列表 */
    loadList() {
      this.listView.params.memberId = this.user.id;
      userApi.goodsFavList(this.listView.params).then(result => {
				if(result.code == constants.SUCCESS){
					utils.pageResultHandle(this.listView, result.data);
					if(result.data.totalCount == 0){
					  this.showList = false;
					}
				}
      })
    },
    /* 选中 */
    checkItem (item) {
     
    }
  }
}
</script>

<style lang="scss">
.usercollect-container{
  padding-top: 5px;
  padding-bottom: 55px;
  .order-goods-list{
    border-bottom: 2px solid #f6f6f6;
    background-color: #fff;
    display: flex;
    align-items: center;
    padding: 10px 20px 10px 15px;
    .goods-sel{
      display: flex;
      justify-content: flex-start;
      margin: 0px 15px 0px 0px;
      .van-checkbox{
        .van-checkbox__icon{
          font-size: 17px;
        }
        .van-checkbox__icon--checked{
          .van-icon{
            background-color: #e9b461;
            border-color: #e9b461;
          }
        }
      }
    }
    .price{
      margin-top: 3px;
    }
  }
  .van-submit-bar{
    width: calc(100% - 24px) !important;
    padding: 0 10px 0 14px;
    .van-submit-bar__bar{
      border-top: 1px solid #f2f2f2;
      padding: 0 7px;
      justify-content: space-between;
      /deep/ .van-submit-bar__button{
        height: 34px;
        width: 80px;
      }
      .van-checkbox{
        margin-left: 4px;
        .van-checkbox__icon{
          height: inherit;
          .van-icon{
            font-size: 14px;
          }
        }
        .van-checkbox__icon--checked{
          .van-icon{
            background-color: #e9b461;
            border-color: #e9b461;
          }
        }
      }
    }
  }
}
</style>
